﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using X.Web;

namespace X.WebSite.Admin.Param
{
    public partial class PriceDetail : AdminPage
    {
        int _Id
        {
            get
            {
                int id = 0;

                if (!string.IsNullOrEmpty(Request.QueryString["Id"]))
                    id = int.Parse(Request.QueryString["Id"]);

                return id;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                X.Entity.PriceInfo priceInfo = Bll.Product.GetPriceInfo(_Id);

                txtLowPrice.Text = priceInfo.LowPrice.ToString();
                txtHightPrice.Text = priceInfo.HightPrice.ToString();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            X.Entity.PriceInfo priceInfo;

            if (0 == _Id)
            {
                priceInfo = new Entity.PriceInfo();

                priceInfo.LowPrice = int.Parse(txtLowPrice.Text);
                priceInfo.HightPrice = int.Parse(txtHightPrice.Text);

                Bll.Product.CreatePrice(priceInfo);
            }
            else
            {
                priceInfo = Bll.Product.GetPriceInfo(_Id);

                priceInfo.LowPrice = int.Parse(txtLowPrice.Text);
                priceInfo.HightPrice = int.Parse(txtHightPrice.Text);

                Bll.Product.UpdatePrice(priceInfo);

            }

            Response.Redirect("PriceList.aspx");
        }
    }
}